package com.person.nacos.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.person.common.CommonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author zhangfc
 * @date 2021/7/24 10:03
 */
@RestController
@Slf4j
public class FlowLimitController {

    @GetMapping("/testA")
    public CommonResult testA() {
        return CommonResult.ok(200, "成功", "-------testA");
    }

    @GetMapping("testB")
    public CommonResult testB() {
        return CommonResult.ok(200, "成功", "--------testB");
    }

    @GetMapping("testD")
    public CommonResult testD() {
        /*try {
            TimeUnit.MILLISECONDS.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }*/


        log.info("测试testD........");
        int i = 1 / 0;
        return CommonResult.ok(200, "成功", "--------testD");
    }

    @GetMapping("/testHotKey")
    @SentinelResource(value = "testHotKey", blockHandler = "dealTestHotKey")
    public CommonResult testE(@RequestParam(value = "p1",required = false) String p1,
                              @RequestParam(value = "p2",required = false) String p2) {
        return CommonResult.ok(200, "success!(*^▽^*)", "testHotKey------");
    }


    public CommonResult dealTestHotKey(String p1, String p2, BlockException exec) {
        return CommonResult.error("failure!o(╥﹏╥)o", "dealTestHotKey------");
    }
}
